#pragma once

#include "ProgressDlg.h"
#include "Dream3DRender.h"
#include "RangeSlider.h"
#include "Worker.h"
#include "ui_vsgUI.h"
#include "ui_vsgUI2.h"
#include <QGraphicsView>
#include <QtWidgets/QMainWindow>
#include <qstandarditemmodel.h>
#include <vsg/all.h>

vsg::ref_ptr<vsg::ubvec4Array2D> updateBaseTexture(std::string path, vsg::ref_ptr<vsg::ubvec4Array2D>& needUpdate, bool bupdate, float value);

void MessageStateProgreeFunction(std::string msg, int state, float per);

class vsgUI : public QMainWindow
{
  Q_OBJECT

public:
  vsgUI(QWidget* parent = nullptr);
  ~vsgUI();

  // 初始化3D场景
  void Init3D();
  // 显示消息
  void ShowStateMessageAndProgress(QString msg, float per);

  virtual bool eventFilter(QObject* watched, QEvent* event) override;

  void ShowPickMessage(vsg::ivec3 ijk, vsg::dvec3 location);

  bool GetPick();

protected:
  QVBoxLayout* mLayout;
  QAction* mActionPan;
  ProgressDlg* mProgressDlg = nullptr;
  Dream3DRender* m3DRender = nullptr;
  class Worker* mpWorker      = nullptr;
  RangeSlider* mRangeSlider   = nullptr;
  vsg::dvec3 mScale           = vsg::dvec3(1, 1, 1);

  void InitWorkThread();

private slots:  // 表示槽函数
  void OpenFile();

  void OpenWell();

  void SwapTexutre();
  void SwapTexutre2();

  void SetTexture1();
  void SetTexture2();

  void GetTable();
  void ComboxTimeStepChange(int index);
  void ShowGrid();

  void ComboxFieldChange(int index);
  void NextField(int index);
  void SetAlpha(int value);

  void ShowGridCell();

  void RemoveCurrentAll();
  void RemoveGridLayer();
  void RemoveWellLayer();

  void receiveMsgFromThread(QString msg, int state, float per);

  void receiveRenderData(RenderData* render, int datatype);

  void SelDyValues(bool bsel);
  void SelStaticValues(bool bsel);

  void SetStaticOrDynamic(bool bsel);

  void Apply();

  void LightSrengthUpdate();

  void SetGridSeeDistance();
  void SetGridLineShow(bool bon);

  void InitFilterGroup();
  void Filter();

  void FilterDebug();

  void InitFilterGroup2();
  void Filter2();

  void InitFilterGroup3();
  void Filter3();

  void InitFilterGroup4();
  void Filter4();

  void FilterReset();

  void SelAll_I();
  void ReSel_I();

  void SelAll_J();
  void ReSel_J();

  void SelAll_K();
  void ReSel_K();

  void ResetScene();

  void ClearScene();

  void SelFilterI(bool bsel);
  void SelFilterJ(bool bsel);
  void SelFilterK(bool bsel);

  void InitDataTree();
  void onCustomContextMenuRequested(const QPoint& pos);
  void TreeSelect(const QModelIndex& index);

private:

  //Ui::vsgUIClass ui;
  Ui::MainWindow ui;
  QProgressBar* progressBar;
  RenderNode mCurrentNode;
  RenderNode mCurrentWellNode;
  QLabel* mpStateMessageLabel = nullptr;
  QLabel* mp3DMessageLabel    = nullptr;

  QString mColorTable1;
  QString mColorTable2;
  bool mNeedResetCamera          = false;
  bool mbFilter                  = false;
  QStandardItemModel* mTreeModel = nullptr;
  QStandardItem* mTreeRoot       = nullptr;
  QStandardItem* mTreeRootWell   = nullptr;
  //由于数据量比较大
  QList<SelectField> mSelectField;
  QString mGridPath;
};
